package com.wc.service.imple;

import com.wc.Dao.EmpDao;
import com.wc.Dao.EmpDaoImpl;
import com.wc.FAKE.DB;
import com.wc.domain.Dept;
import com.wc.domain.Emp;
import com.wc.emu.Role;
import com.wc.service.EmpService;
import com.wc.utils.Md5Util;


/**
 * @ClassName:UserServiceImpl
 * @Author: 鹿建文
 * @Date: 2022/3/22  - 10:33
 * @Describe:
 */
public class EmpServiceImpl implements EmpService {
    EmpDaoImpl empDao = new EmpDaoImpl();


    @Override
    public boolean updateEmp(Emp emp) {
//        boolean res= EmpDao.updateEmp(emp);
        boolean res = empDao.updateEmp(emp);
        return res;
    }

    @Override

    public int login(String account, String password) {
        for (Emp emp : DB.emps) {
            if (emp.getAccount().equals(account)) {
                Integer empno = emp.getEmpno();
                String salt = empDao.getMd5SatltByUserEmpno(empno);
                String encode = Md5Util.encode(password, salt);
                if (emp.getPassword().equals(encode)) {
                    return emp.getEmpno();
                }
            }

        }
        return -1;
    }

    @Override
    public Emp getEmpByEmpno(Integer empno) {
            Emp emp=empDao.selectEmpByEmpNo(empno);

        return emp;
    }

    @Override
    public Role getRoleByEmpno(Integer empno) {
        Emp emp=empDao.selectEmpByEmpNo(empno);

        return emp.getRole();
    }

    @Override
    public Dept getDeptByEmpno(Integer empno) {
        Dept dept = empDao.selectDeptByEmpno(empno);
        return dept;
    }




}
